import { URLParams } from '../../src/js_url';
import { URL } from '../../src/js_url';

function assertEqual(a: any, b: any) {
    if (a !== b) {
      throw new Error(`Assertion failed: ${a} !== ${b}`);
    }
  }

{
    let obj = URL.parseURL('https://example.org:81/a/b/c?query#fragment')
    assertEqual(obj.pathname, '/a/b/c');
    console.log('-------------------------1 done');
}

{
    let obj = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(obj.pathname, "/directory/file");
    console.log('-------------------------2 done');
}

{
    let obj = URL.parseURL("../baz", "http://example.org/foo/bar");
    assertEqual(obj.pathname,  "/baz");
    console.log('-------------------------3 done');
}

{
    let obj = URL.parseURL("/../sca/./path/path/../scasa/jjjjj", "http://www.example.com");
    assertEqual(obj.pathname, "/sca/path/scasa/jjjjj");
    console.log('-------------------------4 done');
}

{
    let obj = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(obj.protocol,  "http:");
    console.log('-------------------------5 done');
}

{
    let base = URL.parseURL("http://www.example.com");
    let url = URL.parseURL("//sca/./path/./scasa#", base);
    assertEqual(url.pathname, "/path/scasa");
    console.log('-------------------------6 done');
}

{
    let base = URL.parseURL("http://www.example.com");
    let url = URL.parseURL("/dire/query", base);
    assertEqual(url.pathname, "/dire/query");
    console.log('-------------------------7 done');
}

{
    let base = URL.parseURL("http://www.example.com");
    let url = URL.parseURL("foo/bar//fragment", base);
    assertEqual(url.pathname, "/foo/bar//fragment");
    console.log('-------------------------8 done');
}

{
    let base = URL.parseURL("http://www.example.com");
    let url = URL.parseURL("/../sca/./path/./s#casa", base);
    assertEqual(url.pathname, "/sca/path/s");
    console.log('-------------------------9 done')
}

{
    let base = URL.parseURL("http://www.example.com");
    let url = URL.parseURL("/../sca/./path/./sca?sa", base);
    assertEqual(url.pathname, "/sca/path/sca");
    console.log('-------------------------10 done')
}

{
    let base = URL.parseURL("http://www.example.com");
    let url = URL.parseURL("", base);
    assertEqual(url.pathname, "/");
    console.log('-------------------------11 done')
}

{
    try {
      let url = URL.parseURL("file://\\/www.example.com");
      assertEqual(url.protocol, "file:");
    } catch (err) {
      console.log('-------------------------12 done ' + err)
    }
}

{
    let url = URL.parseURL("file:///www.example.com");
    assertEqual(url.protocol, "file:");
    console.log('-------------------------13 done')
}

{
    let url = URL.parseURL("http1://www.example.com");
    assertEqual(url.protocol, "http1:");
    console.log('-------------------------14 done')
}

{
    let url = URL.parseURL("http2://www.example.com:22/adfee/kk?a=4#saf");
    assertEqual(url.protocol, "http2:");
    console.log('-------------------------15 done')
}

{
    let url = URL.parseURL("http2://username:password@www.example.com:22/adfee/kk?a=4#saf");
    assertEqual(url.protocol, "http2:");
    console.log('-------------------------16 done')
}

{
    try {
      let url = URL.parseURL("http://");
      assertEqual(url.urlInner.flags[0], 1);
    } catch (err) {
        console.log('-------------------------17 done ' + err)
    }
}

{
    try {
        let url = URL.parseURL("http://username:password@/adfee/kk?a=4#saf");
        assertEqual(url.urlInner.flags[0], 1);
    } catch (err) {
        console.log('-------------------------18 done ' + err)
    }
}

{
    try {
        let url = URL.parseURL("http://username:password@/adfee/kk?a=4#saf", "");
        assertEqual(url.urlInner.flags[0], 1);
    } catch{
        console.log('-------------------------19 done')
    }

}

{
    try {
        let url = URL.parseURL("http://username:password@sda/adfee/kk?a=4#saf", "http://sads/sad");
        assertEqual(url.urlInner.flags[0], 0);
        console.log('-------------------------20 done')
    } catch(err){
        console.log('-------------------------20 error' + err)
    }
}

{
    try {
        let url = URL.parseURL("//fdsa", "http://sad");
        assertEqual(url.urlInner.flags[0], 0);
        console.log('-------------------------21 done')
    } catch(err){
        console.log('-------------------------21 error' + err)
    }
}

{
    try {
        let url = URL.parseURL("-http://username:password@/adfee/kk?a=4#saf");
        assertEqual(url.urlInner.flags[0], 1);
        console.log('-------------------------22 done')
    } catch(err){
        console.log('-------------------------22 error' + err)
    }
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.protocol, "http:");
    console.log('-------------------------23 done')
}

{
    let url = URL.parseURL("ftp://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.protocol, "ftp:");
    console.log('-------------------------24 done')
}

{
    let url = URL.parseURL("https://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.protocol, "https:");
    console.log('-------------------------25 done')
}

{
    let url = URL.parseURL("https://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.protocol, "https:");
    url.protocol = "ftp:";
    assertEqual(url.protocol, "ftp:");
    console.log('-------------------------26 done')
}

{
    let url = URL.parseURL("https://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.protocol, "https:");
    url.protocol = "666";
    assertEqual(url.protocol, "https:");
    console.log('-------------------------27 done')
}

{
    let url = URL.parseURL("https://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.protocol, "https:");
    url.protocol = "-/+";
    assertEqual(url.protocol, "https:");
    console.log('-------------------------28 done')
}

{
    let url = URL.parseURL("https://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.protocol, "https:");
    url.protocol = "file";
    assertEqual(url.protocol, "https:");
    console.log('-------------------------29 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.username, "username");
    console.log('-------------------------30 done')
}

{
    let url = URL.parseURL("http://zhao:password@host:8080/directory/file?query#fragment");
    assertEqual(url.username, "zhao");
    console.log('-------------------------31 done')
}

{
    let url = URL.parseURL("http://skk:password@host:8080/directory/file?query#fragment");
    assertEqual(url.username, "skk");
    console.log('-------------------------32 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.username, "username");
    url.username = "666";
    assertEqual(url.username, "666");
    console.log('-------------------------33 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.username, "username");
    url.username = "";
    assertEqual(url.username, "");
    console.log('-------------------------34 done')
}

{
    let url = URL.parseURL("http://username:11@host:8080/directory/file?query#fragment");
    assertEqual(url.password, "11");
    console.log('-------------------------35 done')
}

{
    let url = URL.parseURL("http://username:23aa@host:8080/directory/file?query#fragment");
    assertEqual(url.password, "23aa");
    console.log('-------------------------36 done')
}

{
    let url = URL.parseURL("http://username@host:8080/directory/file?query#fragment");
    assertEqual(url.password, "");
    console.log('-------------------------37 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.password, "password");
    url.password = "666";
    assertEqual(url.password, "666");
    console.log('-------------------------38 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.password, "password");
    url.password = "";
    assertEqual(url.password, "");
    console.log('-------------------------39 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.host, "host:8080");
    console.log('-------------------------40 done')
}

{
    let url = URL.parseURL("http://username:password@hosthost/directory/file?query#fragment");
    assertEqual(url.host, "hosthost");
    console.log('-------------------------41 done')
}

{
    let url = URL.parseURL("http://username:password@host:199/directory/file?query#fragment");
    assertEqual(url.host, "host:199");
    console.log('-------------------------42 done')
}

{
    let url = URL.parseURL("http://username:password@host:199/directory/file?query#fragment");
    assertEqual(url.host, "host:199");
    url.host = "0.0.0.0.0:199";
    assertEqual(url.host, "0.0.0.0.0:199");
    console.log('-------------------------43 done')
}

{
    let url = URL.parseURL("http://username:password@host:199/directory/file?query#fragment");
    assertEqual(url.host, "host:199");
    url.host = "";
    assertEqual(url.host, "host:199");
    console.log('-------------------------44 done')
}

{
    let url = URL.parseURL("http://username:password@host:199/directory/file?query#fragment");
    assertEqual(url.host, "host:199");
    url.host = "asdzxc:54/";
    assertEqual(url.host, "asdzxc:54");
    console.log('-------------------------45 done')
}

{
    let url = URL.parseURL("http://username:password@host:199/directory/file?query#fragment");
    assertEqual(url.host, "host:199");
    url.href = "http:example.com";
    assertEqual(url.host,  "example.com");
    console.log('-------------------------46 done')
}

{
    let url = URL.parseURL("http://username:password@host:199/directory/file?query#fragment");
    assertEqual(url.host, "host:199");
    url.href = "   http:example.com";
    assertEqual(url.host, "example.com");
    console.log('-------------------------47 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.hostname, "host");
    console.log('-------------------------48 done')
}

{
    let url = URL.parseURL("http://username:password@host123:8080/directory/file?query#fragment");
    assertEqual(url.hostname,  "host123");
    console.log('-------------------------49 done')
}

{
    let url = URL.parseURL("http://username:password@885ssa:8080/directory/file?query#fragment");
    assertEqual(url.hostname, "885ssa");
    console.log('-------------------------50 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.port, "8080");
    console.log('-------------------------51 done')
}

{
    let url = URL.parseURL("http://username:password@host:100/directory/file?query#fragment");
    assertEqual(url.port, "100");
    console.log('-------------------------52 done')
}

{
    let url = URL.parseURL("http://username:password@host/directory/file?query#fragment");
    assertEqual(url.port, "");
    console.log('-------------------------53 done')
}

{
    try {
      let url = URL.parseURL("http://username:password@host:655656/directory/file?query#fragment");
      assertEqual(url.urlInner.flags[0], 1);
    } catch (err) {
      console.log('-------------------------54 done ' + err)
    }
}

{
    try {
      let url = URL.parseURL("http://username:password@host:6c3/directory/file?query#fragment");
      assertEqual(url.urlInner.flags[0], 1);
    } catch (err) {
        console.log('-------------------------55 done ' + err)
    }
}

{
    let url = URL.parseURL("http://username:password@host:100/directory/file?query#fragment");
    assertEqual(url.port, "100");
    url.port = "600?";
    assertEqual(url.port, "600");
    console.log('-------------------------56 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query#fragment");
    assertEqual(url.pathname, "/directory/file");
    console.log('-------------------------57 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory?query#fragment");
    assertEqual(url.pathname, "/directory");
    console.log('-------------------------58 done')
}

{
    let url = URL.parseURL("http2://username:password@host:8080?query#fragment");
    assertEqual(url.pathname,  "");
    console.log('-------------------------59 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080?query#fragment");
    assertEqual(url.urlInner.flags[0], 0);
    console.log('-------------------------60 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080?query#fragment");
    assertEqual(url.pathname, "/");
    url.pathname = "\\D:";
    assertEqual(url.pathname,  "/D:");
    console.log('-------------------------61 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080?query#fragment");
    assertEqual(url.pathname, "/");
    url.pathname = ":\\D:";
    assertEqual(url.pathname, "/:/D:");
    console.log('-------------------------62 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080?query#fragment");
    assertEqual(url.pathname, "/");
    url.pathname = "::";
    assertEqual(url.pathname, "/::");
    console.log('-------------------------63 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080?query#fragment");
    assertEqual(url.pathname, "/");
    url.pathname = "";
    assertEqual(url.pathname, "/");
    console.log('-------------------------64 done')
}

{
    let url = URL.parseURL("file://hostsasf");
    url.pathname = "/askdj";
    assertEqual(url.pathname, "/askdj");
    console.log('-------------------------65 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=qqqq#fragment");
    assertEqual(url.search, "?query=qqqq");
    console.log('-------------------------66 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=qqqq&ll=pp#fragment");
    assertEqual(url.search, "?query=qqqq&ll=pp");
    console.log('-------------------------67 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?ppp9875=77#fragment");
    assertEqual(url.search, "?ppp9875=77");
    console.log('-------------------------68 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?ppp9875=77#fragment");
    assertEqual(url.search, "?ppp9875=77");
    url.search = "";
    assertEqual(url.search, "");
    console.log('-------------------------69 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?ppp9875=77#fragment");
    assertEqual(url.search, "?ppp9875=77");
    url.search = "?444=555";
    assertEqual(url.search, "?444=555");
    console.log('-------------------------70 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?ppp9875=77#fragment");
    assertEqual(url.search, "?ppp9875=77");
    url.search = "444=555";
    assertEqual(url.search, "?444=555");
    console.log('-------------------------71 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?ppp9875=77#fragment");
    assertEqual(url.search, "?ppp9875=77");
    url.search = "?##44=55";
    assertEqual(url.search, "?%23%2344=55");
    console.log('-------------------------72 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#fragment");
    assertEqual(url.hash, "#fragment");
    console.log('-------------------------73 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    assertEqual(url.hash, "#123456");
    console.log('-------------------------74 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    assertEqual(url.hash, "#123456");
    url.hash = "";
    assertEqual(url.hash, "");
    console.log('-------------------------75 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    assertEqual(url.hash, "#123456");
    url.hash = "#445566";
    assertEqual(url.hash, "#445566");
    console.log('-------------------------76 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    assertEqual(url.hash, "#123456");
    url.hash = "445566";
    assertEqual(url.hash,  "#445566");
    console.log('-------------------------77 done')
}

{
    let url = URL.parseURL("http://[1080:0:0:0:8:800:200C:417A]/index.html");
    assertEqual(url.urlInner.flags[0], 0);
    console.log('-------------------------78 done')
}

{
    let url = URL.parseURL("http://0377.0xff.255.1:80/index.html");
    assertEqual(url.urlInner.flags[0], 0);
    console.log('-------------------------79 done')
}

{
    try {
      let url = URL.parseURL("http://[1080:0:0:0:8:800:200C.417A]/index.html");
      assertEqual(url.urlInner.flags[0], 1);
    } catch (err) {
      console.log('-------------------------80 done ' + err)
    } 
}

{
    let url = URL.parseURL("http://0377.0xff.255.1:80/index.html");
    assertEqual(url.urlInner.flags[0], 0);
    console.log('-------------------------81 done')
}

{
    try {
      let url = URL.parseURL("http://192.168.259.551:80/index.html");
      assertEqual(url.urlInner.flags[0], 1);
    } catch (err) {
      console.log('-------------------------82 done ' + err)
    } 
}

{
    let url = URL.parseURL("http://0377.0xff.255.1:80/index.html");
    url.hostname = "host";
    assertEqual(url.hostname, "host");
    console.log('-------------------------83 done')
}

{
    let url = URL.parseURL("http://0377.0xff.255.1:80/index.html");
    url.hostname =  "";
    assertEqual(url.hostname, "255.255.255.1");
    console.log('-------------------------84 done')
}

{
    let url = URL.parseURL("file:///www.example.com");
    url.hostname = "localhost/";
    assertEqual(url.urlInner.flags[0], 0);
    console.log('-------------------------85 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?foo=1&bar=2");
    assertEqual(url.search, "?foo=1&bar=2");
    console.log('-------------------------86 done')
}

{
    let url = URL.parseURL("https://example.com?d=value1&c=value2&b=大&4=key4");
    assertEqual(url.search, "?d=value1&c=value2&b=%E5%A4%A7&4=key4");
    console.log('-------------------------87 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?你好=china#qwer=da");
    assertEqual(url.search, "?%E4%BD%A0%E5%A5%BD=china");
    console.log('-------------------------88 done')
}

{
    let params = new URLParams();
    params.append("ma", "jk");
    assertEqual(params.toString(), "ma=jk");
    console.log('-------------------------89 done')
}

{
    let params = new URLParams();
    params.append("ma 大", "jk￥");
    assertEqual(params.toString(), "ma+%E5%A4%A7=jk%EF%BF%A5");
    console.log('-------------------------90 done')
}

{
    let params = new URLParams();
    params.append("foo~!@#$%^&*()_+-=", "jk");
    assertEqual(params.toString(), "foo%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D=jk");
    console.log('-------------------------91 done')
}

{
    let params = new URLParams();
    params.append('', "jk");
    assertEqual(params.get('jk'), undefined);
    console.log('-------------------------92 done')
}

{
    let params = new URLParams();
    params.append("foo~!@#$%^&*()_+-=", '');
    assertEqual(params.get('foo~!@#$%^&*()_+-='), '');
    console.log('-------------------------93 done')
}

{
    let params = new URLParams();
    params.append("foo~!@#$%^&*()_+-=", "jk");
    params.delete("foo~!@#$%^&*()_+-=");
    assertEqual(params.toString(), "");
    console.log('-------------------------94 done')
}

{
    let params = new URLParams();
    params.append("foo~!@#$%^&*()_+-=", "jk");
    params.append("ma", "jk");
    params.delete("foo~!@#$%^&*()_+-=");
    assertEqual(params.toString(), "ma=jk");
    console.log('-------------------------95 done')
}

{
    let params = new URLParams();
    params.append("foo~!@#$%^&*()_+-=", "jk");
    params.append("ma", "jk");
    params.delete("foo~!@#$%^&*()_+-=");
    params.delete("ma");
    assertEqual(params.toString(), "");
    console.log('-------------------------96 done')
}

{
    let params = new URLParams();
    params.append("foo~!@#$%^&*()_+-=", "jk");
    params.append("ma", "jk");
    params.delete("foo~!@#$%^&*()_+-=");
    params.delete('');
    assertEqual(params.get('ma'), "jk");
    console.log('-------------------------97 done')
}

{
    let params = new URLParams();
    params.append("foo~!@#$%^&*()_+-=", "jk");
    assertEqual(params.get('foo~!@#$%^&*()_+-='), "jk");
    console.log('-------------------------98 done')
}

{
    let params = new URLParams();
    assertEqual(params.get('jk'), undefined);
    console.log('-------------------------99 done')
}

{
    let params = new URLParams();
    assertEqual(params.get("hello, \U0001F600 world!"), undefined);
    console.log('-------------------------100 done')
}

{
    let params = new URLParams([["foo~!@#$%^&*()_+-=","jk"]]);
    assertEqual(params.get("hello, \U0001F600 world!"), undefined);
    console.log('-------------------------101 done')
}

{
    let params = new URLParams();
    params.append("foo~!@#$%^&*()_+-=", "jk");
    assertEqual(params.getAll('jk').length, 0);
    console.log('-------------------------102 done')
}

{
    let params = new URLParams();
    params.append("#[%@]", "jk");
    params.append("ma1", "jk1");
    assertEqual(params.getAll('jk').length, 0);
    console.log('-------------------------103 done')
}

{
    let params = new URLParams();
    params.append("ma", "jk");
    assertEqual(params.getAll('ma')[0], 'jk');
    console.log('-------------------------104 done')
}

{
    let params = new URLParams();
    params.append("你好", "안녕하세요");
    params.append("[saa]", "{aas}");
    assertEqual(params.get('你好'), '안녕하세요');
    console.log('-------------------------105 done')
}

{
    let params = new URLParams();
    assertEqual(params.has('你好'), false);
    console.log('-------------------------106 done')
}

{
    let params = new URLParams();
    params.append("ma1", "jk1");
    params.set('ma1', 'jk');
    assertEqual(params.get('ma1'), 'jk');
    console.log('-------------------------107 done')
}

{
    let params = new URLParams();
    params.append("ma", "jk");
    params.append("foo~!@#$%^&*()_+-=", "jk1");
    params.sort();
    assertEqual(params.toString(), "foo%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D=jk1&ma=jk");
    console.log('-------------------------108 done')
}

{
    let params = new URLParams();
    params.append("ma", "jk");
    params.append("foo~!@#$%^&*()_+-=", "jk1");
    params.append("a", "jk2");
    params.sort();
    assertEqual(params.toString(), "a=jk2&foo%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D=jk1&ma=jk");
    console.log('-------------------------109 done')
}

{
    let params = new URLParams();
    assertEqual(params.has('ma'), false);
    console.log('-------------------------110 done')
}

{
    let params = new URLParams();
    params.append("ma", "jk");
    params.append("foo~!@#$%^&*()_+-=", "jk1");
    params.append("a", "jk2");
    let keys = params.keys();
    assertEqual(keys.next().value, "ma");
    assertEqual(keys.next().value, "foo~!@#$%^&*()_+-=");
    assertEqual(keys.next().value, "a");
    console.log('-------------------------111 done')
}

{
    let params = new URLParams();
    params.append("ma", "jk");
    params.append("foo~!@#$%^&*()_+-=", "jk1");
    params.append("a", "jk2");
    let values = params.values();
    assertEqual(values.next().value, "jk");
    assertEqual(values.next().value, "jk1");
    assertEqual(values.next().value, "jk2");
    console.log('-------------------------112 done')
}

{
    let params = new URLParams();
    params.append("ma", "jk");
    params.append("你好", "jk1");
    params.append("a", "jk2");
    let result = params.entries();
    result.next();
    result.next();
    result.next();
    assertEqual(result.next().value, null);
    console.log('-------------------------113 done')
}

{
    let params = new URLParams();
    let result = params.values();
    assertEqual(result.next().done, true);
    console.log('-------------------------114 done')
}

{
    let params = new URLParams();
    params.append("你好", "jk1");
    let result = params.values();
    assertEqual(result.next().done, false);
    console.log('-------------------------115 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    let params = url.params;
    for (const [key, value] of params.entries()) {
        assertEqual(key, "query");
        assertEqual(value, "pppppp");
      }
    console.log('-------------------------116 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    url.hash = 'saaf^as\tk\njf'
    assertEqual(url.hash, "#saaf^askjf");
    console.log('-------------------------117 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    assertEqual(url.origin, "http://host:8080");
    url.host = 'salkjf.com';
    assertEqual(url.origin, "http://salkjf.com:8080");
    console.log('-------------------------118 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    assertEqual(url.pathname, "/directory/file");
    url.pathname = 'sasf/s?dc#j/mm^h';
    assertEqual(url.pathname, "/sasf/s%3Fdc%23j/mm^h");
    console.log('-------------------------119 done')
}

{
    let url = URL.parseURL("http://username:password@host:8080/directory/file?query=pppppp#123456");
    assertEqual(url.port, "8080");
    url.port = '98\t5\r6';
    assertEqual(url.port, "9856");
    console.log('-------------------------120 done')
}

{
    let url = URL.parseURL("http://username:password@host:443/directory/file?query=pppppp#123456");
    assertEqual(url.origin, "http://host:443");
    url.protocol = 'ht\tt\nps:';
    assertEqual(url.origin, "https://host");
    assertEqual(url.port, "");
    console.log('-------------------------121 done')
}

{
    let url = URL.parseURL("http://username:password@host:443/directory/file?query=pppppp#123456");
    assertEqual(url.search, "?query=pppppp");
    url.search = 'ad/sd=ss`\'c\rc\tc\nc'
    assertEqual(url.search, "?ad/sd=ss`%27cccc");
    console.log('-------------------------122 done')
}

{
    let url = URL.parseURL("http://aas@asdgfv.hh:443/index.html?sad=ss中国s");
    assertEqual(url.toString(), "http://aas@asdgfv.hh:443/index.html?sad=ss%E4%B8%AD%E5%9B%BDs");
    url.search = 'ad/sd=s中国s`\'cc\tc\rc';
    assertEqual(url.toString(), "http://aas@asdgfv.hh:443/index.html?ad/sd=s%E4%B8%AD%E5%9B%BDs`%27cccc");
    console.log('-------------------------123 done')
}

{
    let params = new URLParams('aa=%E4%B8%AD%E5%9B%BD%BD');
    assertEqual(params.toString(), "aa=%E4%B8%AD%E5%9B%BD%EF%BF%BD")
    assertEqual(params.get('aa'), "中国�")
    console.log('-------------------------124 done')
}